<h1>Optional Additional Parameters</h1><p>When you are creating your API settings file, there are a range of optional parameters that you can declare for each of your endpoints. The optional parameters are as follows:</p><h2>Required Fields</h2><ul><li><strong>required_fields</strong>: This will be an array of key value pairs, with each pair representing the name and the label for a required field. The code below declares an endpoint that has 'id' as a required field:</li></ul><p>[code]"Exists": {
  "url_segments": "api/exists/members/{id}",
  "request_type": "GET",
  "description": "Check if instance exists",
  "required_fields": [
    {
      "name": "id",
      "label": "ID"
    }
  ]
}
[/code]</p><div class="alert alert-warning">If you have a close look at the url_segments, above, you'll notice that the final segment is for 'id' and it's inside curly brackets. When you see <em>this</em> type of pattern in the URL segments, it means that we are expecting a value (in this case, 'id') to be passed in via the URL.</div></p><h2>Before Hook</h2><ul><li><strong>beforeHook</strong>: The beforeHook parameter can be used to declare a method that should intercept the inbound HTTP request <em>before</em> allowing the request to reach the main endpoint method. Below is an example of an endpoint that has a beforeHook property of '_prep_password'. This endpoint will intercept the inbound HTTP request and run it through a method, on the loaded module, named <strong>_prep_password()</strong>. </li></ul>

<p>[code]"Update": {
  "url_segments": "api/update/trongate_administrators/{id}",
  "request_type": "PUT",
  "description": "Update a database record",
  "enableParams": true,
  "required_fields": [
    {
      "name": "id",
      "label": "ID"
    }
  ],
  "authorization":{
    "roles": [
    "admin"
    ]
  },
  "beforeHook": "_prep_password"
}[/code]</p><div class="alert alert-warning">The underscore at the start of _prep_password() means that the method is 'protected'. In other words, it cannot be invoked by going to a particular URL.</div></p><h2>After Hook</h2><ul><li><strong>afterHook</strong>: The afterHook parameter can be used to declare a method that should receive the outbound server response <em>before</em> the response has been served to the end user. Below is an example of an endpoint that has an afterHook property of '_prep_date'. This endpoint will intercept the outbound HTTP response and run it through a method, on the loaded module, named <strong>_prep_date()</strong>. Our visualisation here would be a scenario where a date/time fetched from a database, such as a Unix timestamp, is to be formatted before being presented to the end user.</li></ul><p>[code]"Fetch Info": {
  "url_segments": "fetch/{id}",
  "request_type": "GET",
  "description": "Fetch a database record",
  "enableParams": true,
  "required_fields": [
    {
      "name": "id",
      "label": "ID"
    }
  ],
  "authorization":{
    "roles": [
    "admin"
    ]
  },
  "afterHook": "_prep_date"
}[/code]</p><div class="alert alert-warning">Again, you can see that the after hook's method name begins with an underscore. This means that the method is protected.</div></p><p>Before hooks and after hooks are important. Let's explore them in a little more detail!</p>